package com.yinuo.common;

import org.apache.log4j.Logger;

import java.util.Properties;

public class SystemDict
{
    private static final Logger LOGGER = Logger.getLogger(SystemDict.class);
    
    private static final String DEFAULT_FILENAME = "app.ini";
    
    private static final Properties proper = new Properties();
    
    private static volatile boolean initFlag = false;
    
    public static synchronized void loadSystemProperty()
    {
        proper.clear();
        
        try
        {
            proper.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(DEFAULT_FILENAME));
        }
        catch (Exception e)
        {
            LOGGER.error(e, e);
        }
        
        initFlag = true;
    }
    
    public static String getSystemDict(String dictName)
    {
        if (initFlag)
        {
            return proper.getProperty(dictName);
        }
        else
        {
            loadSystemProperty();
            return proper.getProperty(dictName);
        }
    }
}
